Welcome Guest | Sign in | Register

Home > Java Programming > Final and Datatypes > Questions and Answers

01. Class F
{
Static void test(int I,int j){
System.out.println(“integer”);
}
Static void test(byte …b){
System.out.println(“byte”);
}

Public static void main(String args[]){
byte s=10;
test(s,s);
}
}

A. compile time error B. runtime error
C. byte D. 0

Answer and Explanation

Answer: byte

Explanation:
Byte…b is called var-args(variable arguments).from main() when we call test(s,s) then test(byte…b) will execute.. to call test(byte…b) you can pass any number of parameters, but it should be of type byte as per the above example.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
02. Class F
{
Static void test(Byte I,Byte j){
System.out.println(“BByte”);
}
Static void test(byte …b){
System.out.println(“byte”);
}

Public static void main(String args[]){
byte s=10;
test(s,s);
}
}
A. compile time error B. runtime error
C. BByte D. byte

Answer and Explanation

Answer: byte

Explanation:
Here test(s,s) will call test(byte…b) because these two are of type primitive.where as test(Byte , Byte) is of type class so it will not get called.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
03. Class w{
Public static void main(String agrs[]){
System.out.println(“hello”);
}

Public static void main(String agrs[]){
System.out.println(“hello”);
}

}
A. hello B. compile time error
C. runtime error D. none of the above

Answer and Explanation

Answer: compile time error

Explanation:
Duplicate main() method. In a single class we cant have two main() methods..

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
04. Class F
{
Static void test(int j){
System.out.println(“int”);
}
Static void test(byte b){
System.out.println(“byte”);
}

Static void test(byte… b){
System.out.println(“byte-varargs”);
}


Public static void main(String args[]){
byte s=10;
test(s);
}
}
A. compile time error

B. byte-varargs
C. int D. byte

Answer and Explanation

Answer: byte

Explanation:
From main() we are calling test(s) by passing only one parameter , first it will check do we have test(byte b) with one parameter , if there is no test() with one parameter then it will call test(byte …b), if only one argument is there then it will call that method only.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum



Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved 2012-2015 SoftLucent.